#include "stdafx.h"
#include "TestDmap.h"
#include "TimeSpanTest.h"
#include "FuncGetLoops.h"
#include "TestIStorage.h"

TestDmap::TestDmap()
{
	//TimeSpanTest tt;

	//m_size = 1000000;

	//m_pl.pts.clear();

	//for (int i = 0; i < m_size; i++)
	//{
	//	PointTest* pp = new PointTest();
	//	pp->x = i;
	//	pp->y = i + 1;
	//	pp->id = i;

	//	m_pl.pts.push_back(*pp);

	//	//m_mpPoint.insert(i, pp);
	//}

	//tt.stop2(_T("t2"));
}

TestDmap::~TestDmap()
{
}

void TestDmap::AddPoly(PointTest ptStart)
{
	//m_size = 10000;

	//m_pl.pts.clear();

	//for (int i = 0; i < m_size; i++)
	//{
	//	PointTest pp(ptStart.x + i, ptStart.y + i);
	//	m_pl.pts.push_back(pp);
	//}

	//CString cs;
	//cs.Format(_T("cs%d"), (int)ptStart.x);
	//m_mapPolys.insert(cs, &m_pl);
}

void TestDmap::Test()
{
	//TestIStorage tt;

	//tt.save(_T("d:\\test.xxx"));

	//tt.load(_T("d:\\test.xxx"));

	FuncGetLoops::Init();

	DPoint3d ps(0, 0, 0), pe(1000, 0, 0);
	FuncGetLoops::AppendSeg(ps, pe);

	ps.set(100, -100, 0);
	pe.set(100, 2000, 0);
	FuncGetLoops::AppendSeg(ps, pe);

	ps.set(0, 100, 0);
	pe.set(1000, 100, 0);
	FuncGetLoops::AppendSeg(ps, pe);

	ps.set(600, -100, 0);
	pe.set(600, 2000, 0);
	FuncGetLoops::AppendSeg(ps, pe);

	ps.set(100, 100, 0);
	pe.set(600, 0, 0);
	FuncGetLoops::AppendSeg(ps, pe);

	FuncGetLoops::DoFindLoop();

	vector<loopResult> lps;
	FuncGetLoops::GetResultAndClose(lps);

	for (auto lp : lps)
	{
		for (auto seg : lp.m_ChildSegIds)
		{
			DPoint3d ps = seg.resultSeg.ps;
			DPoint3d pe = seg.resultSeg.pe;
			int kkk = 0;
		}
	}

	//int len = 100;
	//for (int i = 0; i < len; i++)
	//{
	//		PointTest p1(0, 2*(i+1));
	//		AddPoly(p1);
	//}
}

PointTest TestDmap::FindPtById(UINT32 id)
{
	return FindPtByIdOld(id);
	//PointTest* pp = m_mpPoint.getAt(id);

	//return *pp;
}

PointTest TestDmap::FindPtByIdOld(UINT32 id)
{
	int len = m_pl.pts.size();
	for (int i = 0; i < len; i++)
	{
		if (id == m_pl.pts[i].id)
		{
			return m_pl.pts[i];
		}
	}

	PointTest pp(0,0);
	return pp;
}
